const bcrypt = require('bcrypt');

// 生成密码哈希
async function hashPassword(password) {
  try {
    const hashedPassword = await bcrypt.hash(password, 10);
    return hashedPassword;
  } catch (error) {
    throw new Error('Failed to hash password');
  }
}

// 验证密码
async function comparePasswords(password, hashedPassword) {
  try {
    const isPasswordValid = await bcrypt.compare(password, hashedPassword);
    return isPasswordValid;
  } catch (error) {
    throw new Error('Failed to compare passwords');
  }
}

module.exports = {
  hashPassword,
  comparePasswords,
};
